package com.zone.demo.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zone.demo.dto.Account;
import com.zone.demo.dto.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

/**
* Description
* @author nixin
* @date 2021/7/8 21:44
* @param
* @return
*/

public interface UserMapper extends BaseMapper<User> {

    /**
    * Description 通过用户名字获取账户信息
    * @author nixin
    * @date 2021/7/8 21:44
    * @param
    * @return com.zone.demo.dto.Account
    */

    @Select("SELECT * FROM account Left JOIN user ON user.acid  = account.account_id where user.name = #{name}")
    Account getAmountByName(String name);
    /**
    * Description 创建user表单
    * @author nixin
    * @date 2021/7/8 21:45
    * @param
    * @return void
    */

    @Select("CREATE TABLE IF NOT EXISTS `user`(\n" +
            "     uid 		 INT(12)      COMMENT \"序号\",\n" +
            "     name		 VARCHAR(10)  COMMENT \"名字\",\n" +
            "     sex 		 CHAR         COMMENT\"性别 M for male F for female\",\n" +
            "     acid       INT(9)      COMMENT\"账号id\",\n" +
            "     gmt_create DATETIME     COMMENT\"创建时间\",\n"+
            "     gmt_modified DATETIME COMMENT\"更新时间\", \n"+
            "     PRIMARY KEY (`uid`)\n" +
                    ")ENGINE=InnoDB DEFAULT CHARSET=utf8;\n")
    void createTableUser();

    /**
    * Description 创建账户表单
    * @author nixin
    * @date 2021/7/8 21:45
    * @param
    * @return void
    */

    @Select("CREATE TABLE IF NOT EXISTS `account`(\n" +
            "    account_id    INT(12)   COMMENT \"账号\",\n" +
            "    amount        INT(20)  COMMENT \"账户余额\",\n" +
            "    phone_number  INT(11)  COMMENT \"预留手机\",\n" +
            "    gmt_create    DATETIME COMMENT \"创建时间\",\n" +
            "    gmt_modified  DATETIME COMMENT \"更新时间\",\n" +
            "    PRIMARY KEY (`account_id`)\n" +
            ")ENGINE=InnoDB DEFAULT CHARSET=utf8;\n")
    void createTableAccount();


    /**
    * Description 添加记录到user
    * @author nixin
    * @date 2021/7/8 21:45
    * @param uid:
    * @param name:
    * @param sex:
    * @param acid:
    * @param gmtCreate:
    * @param gmtModified:
    * @return void
    */

    @Select("insert into user(uid,name,sex,acid,gmt_create,gmt_modified) values(#{uid},#{name},#{sex},#{acid},#{gmtCreate},#{gmtModified})")
    void insertDataToUser(Integer uid, String name, String sex, Integer acid , Date gmtCreate, Date gmtModified);


    /**
    * Description 添加记录到account
    * @author nixin
    * @date 2021/7/8 21:49
    * @param accountId:
    * @param amount:
    * @param phoneNumber:
    * @param gmtCreate:
    * @param gmtModified:
    * @return void
    */

    @Select("insert into account(account_id,amount,phone_number,gmt_create,gmt_modified) values(#{accountId},#{amount},#{phoneNumber},#{gmtCreate},#{gmtModified})")
    void insertDataToAccount(Integer accountId,Integer amount ,String phoneNumber,Date gmtCreate,Date gmtModified);

    /**
    * Description 查询所有用户信息
    * @author nixin
    * @date 2021/7/8 21:50
    * @param page:
    * @return com.baomidou.mybatisplus.core.metadata.IPage<com.zone.demo.dto.User>
    */


    @Select("SELECT * FROM USER")
    IPage<User> getAllUser(Page<User> page);
    /**
    * Description 查询所有账户信息
    * @author nixin
    * @date 2021/7/8 21:51
    * @param page:
    * @return com.baomidou.mybatisplus.core.metadata.IPage<com.zone.demo.dto.Account>
    */

    @Select("SELECT * FROM ACCOUNT")
    IPage<Account> getAllAccount(Page<Account> page);
}
